<?php

/**
 * This file is part of the Codizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Codizer Core Team <team@codizer.org>
 * @package     Codizer
 */

abstract class f_form_Checker
{
	protected $params;
	protected $value;
	protected $errormsg = "Error";
	protected $formValues;
	
	/**
	 * @return f_form_Checker
	 */
	public function __construct($params, $formValues)
	{	
		$this->params = $params;		
		$this->formValues = $formValues;
		
		// Set Error Message 
		if(isset($params['errormsg']))
		{
			$this->errormsg = $params['errormsg'];
		}
		
		// Set Value
		if(isset($params['value']))
		{
			$this->value = $params['value'];
		}
			
		return $this;
	}	
	
	abstract public function check();
	
	public function getParameters()
	{
		return $this->params;
	}
	
	public function setParameters($params)
	{
		$this->params = $params;
		return $this;
	}

	public function getAttribute($key)
	{
		if(isset($this->params[$key]))
		{
			return $this->params[$key];
		}
		return null;
	}
	
	public function getFormValues()
	{
		return $this->formValues;
	}
	
	public function getFormValue($key)
	{
		if(isset($this->formValues[$key]))
		{
			return $this->formValues[$key];			
		}
		return null;
	}
	
	public function getValue()
	{
		return $this->value;
	}
	
	public function setValue($value)
	{
		$this->value = $value;
		return this;
	}
	
	public function getErrorMessage()
	{
		return $this->errormsg;
	}
	
	public function setErrorMessage($message)
	{
		$this->errormsg = $message;
		return this;
	}
}